/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MUDCREATURE_H
#define MUDCREATURE_H

#include "MudMobile.h"
#include "MudMobileRegenTask.h"
#include "MudObjectTask.h"
#include "TaskQueue.h"
#include "Global.h"
#include "Messages.h"

namespace Chronos {

class MudPlayer;

class MudCreature : public MudMobile {
public:
    MudCreature(const std::string& name_
				, const std::string& descr_
				, int maxHealth_
				, int speed_
				, int maxDamage_
				, int hitChance_
                , bool aggro_=false);
    MudCreature(const MudCreature& rhs);

    virtual void accept(CmdVisitor& v);
    virtual bool handleRoomEvent(MudMobile& mobile, RoomEvent event);
	virtual void handleTrigger(MudTriggerAction action, MudMobile* cause, const std::string& msg);
    
    unsigned int doEmote();
    void setChatInterval(unsigned int min, unsigned int max);
    void addChat(const std::string& msg, unsigned int weight = 1);

    virtual unsigned int doCombat();
    virtual void miss(MudMobile& source);
    virtual bool takeDmg(MudMobile& source, unsigned int dmg);

    bool isAggro() const;
protected:
    bool aggressive;

    Messages messages;
    unsigned int minChatInterval;
    unsigned int maxChatInterval;

    MudCreature& operator= (const MudCreature&);
};


class CreatureFactory {
public:
    CreatureFactory(const MudCreature& t) : prototype(t) {} 
    virtual ~CreatureFactory() {}
    MudCreature& create() const {
        MudCreature* creature = new MudCreature(prototype);
        Global<TaskQueue>()->addTask(new MudMobileRegenTask(*creature), 1);
        Global<TaskQueue>()->addTask(new MudObjectFuncTask<MudCreature>(*creature, &MudCreature::doEmote), 1);
        return *creature;
    }
private:
    const MudCreature prototype;
};

}

#endif

